package com.monkeyboy.controller;

import com.monkeyboy.common.GlobalException;
import com.monkeyboy.common.ParamData;
import com.monkeyboy.common.ResStatusEnum;
import com.monkeyboy.common.dto.LayuiData;
import com.monkeyboy.common.dto.ResData;
import com.monkeyboy.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;

/**
 * @Author Gavin
 * @date 2021.01.15 09:40
 */
@RestController
@RequestMapping("/system/user")
public class UserController {
    @Autowired
    private UserService userService;

    /**
     * 获取所有用户
     *
     * @param request
     * @return
     */
    @RequestMapping("/getAllUsers")
    public LayuiData getAllUsers(HttpServletRequest request) throws Exception {
        LayuiData res = new LayuiData();
        ParamData param = new ParamData(request);
        return userService.getAllUsers(param);
    }

    /**
     * 添加用户
     *
     * @param request
     * @return
     * @throws Exception
     */
    @PostMapping("/addUser")
    public ResData addUser(HttpServletRequest request) throws Exception {
        return userService.addUser(new ParamData(request));
    }

    /**
     * 删除用户
     *
     * @param user_id
     * @return
     * @throws Exception
     */
    @GetMapping("/delUser")
    public ResData delUser(String user_id) throws Exception {
        return userService.delUser(user_id);
    }
}
